home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2005 May / PC för Alla 0505.iso / fullversioner / realsoft3d / data1.cab / Scripting / scripts / js / myclasses / toolbars / mycreation.js next >
Encoding:
Text File  |  2005-04-04  |  6.1 KB  |  225 lines

  1.  
  2. //
  3. // Description:
  4. //     Tool Bar example demonstrating now to derive new toolbar classes from
  5. //      'toolbar.js' base class. Defines new class called myCreationTools. 
  6. //
  7. // Super class:
  8. //      myclasses/toolbars/toolbar.js
  9. //
  10. // Constructor:
  11. //      toolbar = new myCreationTools();
  12. //
  13. // Attributes:
  14. //      --
  15. //
  16. // Methods:
  17. //      --
  18. //
  19.  
  20. include("myclasses/toolbars/mytoolbar.js"); // super class
  21. include("real/layer/r3prilay.js");          // geometrics objects layer 
  22.  
  23. // geometric objects
  24. include("real/objects/r3sphere.js");
  25. include("real/objects/r3nurbs.js");
  26. include("real/objects/r3numesh.js");
  27. include("real/objects/r3subdiv.js");
  28. include("real/objects/r3rect.js");
  29. include("real/objects/r3cube.js");
  30. include("real/objects/r3pyrami.js");
  31. include("real/objects/r3cone.js");
  32. include("real/objects/r3camera.js");
  33.  
  34. function mycreRect(button, event, value)
  35. {
  36.     rect = new r3Rect(0);
  37.  
  38.     rect.SetP0(new r3Vect(0.0, 0.0, 0.0));
  39.     rect.SetP1(new r3Vect(0.1, 0.0, 0.0));
  40.     rect.SetP2(new r3Vect(0.0, 0.1, 0.0));
  41.     button.layer.LOCKEXCLUSIVE(0);
  42.     button.layer.INSERT(0, 0, rect);
  43.     button.layer.RELEASE(0);
  44. }
  45.  
  46. function mycreCube(button, event, value)
  47. {
  48.     cube = new r3Cube(0);
  49.  
  50.     cube.SetP0(new r3Vect(0.0, 0.0, 0.0));
  51.     cube.SetP1(new r3Vect(0.1, 0.0, 0.0));
  52.     cube.SetP2(new r3Vect(0.0, 0.1, 0.0));
  53.     cube.SetP3(new r3Vect(0.0, 0.0, 0.1));
  54.     button.layer.LOCKEXCLUSIVE(0);
  55.     button.layer.INSERT(0, 0, cube);
  56.     button.layer.RELEASE(0);
  57. }
  58.  
  59. function mycrePyramid(button, event, value)
  60. {
  61.     pyram = new r3Pyramid(0);
  62.  
  63.     pyram.SetP0(new r3Vect(0.0, 0.0, 0.0));
  64.     pyram.SetP1(new r3Vect(0.2, 0.0, 0.0));
  65.     pyram.SetP2(new r3Vect(0.0, 0.2, 0.0));
  66.     pyram.SetP3(new r3Vect(0.1, 0.1, 0.1));
  67.     button.layer.LOCKEXCLUSIVE(0);
  68.     button.layer.INSERT(0, 0, pyram);
  69.     button.layer.RELEASE(0);
  70. }
  71.  
  72. function mycreCone(button, event, value)
  73. {
  74.     cone = new r3Cone(0);
  75.  
  76.     // define apex (center) and axes for the cone 
  77.     cone.SetCenter(new r3Vect(0.0, 0.0, 0.0));
  78.     cone.SetA(new r3Vect(0.1, 0.0, 0.0));
  79.     cone.SetB(new r3Vect(0.0, 0.1, 0.0));
  80.     cone.SetC(new r3Vect(0.0, 0.0, 0.1));
  81.  
  82.     // define clipping plane (one point and two vectors defining plane)
  83.     cone.SetP(new r3Vect(0.0, 0.0, 0.1));
  84.     cone.SetM(new r3Vect(1.0, 0.0, 0.0));
  85.     cone.SetN(new r3Vect(0.0, 1.0, 0.0));
  86.     button.layer.LOCKEXCLUSIVE(0);    
  87.     button.layer.INSERT(0, 0, cone);
  88.     button.layer.RELEASE(0);
  89. }
  90.  
  91. function mycreCamera(button, event, value)
  92. {
  93.     cam = new r3Camera(0);
  94.  
  95.     cam.SetPosition(new r3Vect(0.2, 0.0, 0.0));
  96.     cam.SetDirection(new r3Vect(0.0, 0.0, 0.0));
  97.     cam.SetUp(new r3Vect(0.1, 0.1, 0.0));
  98.     cam.SetSide(new r3Vect(0.1, 0.0, 0.1));
  99.     cam.SetName("Left view");
  100.     button.layer.LOCKEXCLUSIVE(0);
  101.     button.layer.INSERT(0, 0, cam);
  102.     button.layer.RELEASE(0);
  103. }
  104.  
  105. function mycreSphere(button, event, value)
  106. {
  107.     sphere = new r3Sphere(0);
  108.  
  109.     sphere.SetCenter(new r3Vect(0.1, 0.0, 0.0));
  110.     sphere.SetRadius(0.1);
  111.     sphere.SetColor(new r3Vect(1.0, 0.0, 0.0));
  112.     sphere.SetName("My cool sphere");
  113.     button.layer.LOCKEXCLUSIVE(0);
  114.     button.layer.INSERT(0, 0, sphere);
  115.     button.layer.RELEASE(0);
  116. }
  117.  
  118. // create a nurbs curve
  119.  
  120. function mycreNurbs(button, event, value)
  121. {
  122.     pcount = 10;
  123.     p = new r3Vect();
  124.     
  125.     nurbs = new r3Nurbs(0);
  126.     nurbs.SetOrder(4);
  127.     nurbs.SetCount(pcount);
  128.     nurbs.SetClosed(FALSE);
  129.  
  130.     for(i = 0; i < pcount; i++) {
  131.         p.set(0.1 * Math.sin(10 * Math.PI * i / pcount), 
  132.               0.1 * Math.cos(10 * Math.PI * i / pcount), 
  133.               0.1 * i / pcount);
  134.         nurbs.SETPOINT(i, p);
  135.     }    
  136.     button.layer.LOCKEXCLUSIVE(0);
  137.     button.layer.INSERT(0, 0, nurbs);
  138.     button.layer.RELEASE(0);
  139. }
  140.  
  141. // create a nurbs mesh
  142.  
  143. function mycreNumesh(button, event, value)
  144. {
  145.     p = new r3Vect();
  146.     knots_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 6.0, 6.0];
  147.     knots_v = [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0];
  148.     var count_u = 9;
  149.     var count_v = 5;
  150.     
  151.     mesh = new r3Numesh(0);
  152.     mesh.SetOrderU(4);
  153.     mesh.SetOrderV(4);
  154.     mesh.SetCountU(count_u);
  155.     mesh.SetCountV(count_v);
  156.     mesh.SetClosedU(FALSE);
  157.     mesh.SetClosedV(FALSE);
  158.     mesh.SetKnotsU(knots_u);
  159.     mesh.SetKnotsV(knots_v);
  160.     
  161.     for(v = 0; v < count_v; v++) {
  162.         for(u = 0; u < count_u; u++) {
  163.             p.x = 0.1 * u / count_u;
  164.             p.y = 0.1 * v / count_v + 0.01 * Math.sin(Math.PI * 2.0 * u / count_v);
  165.             p.z = 0.0;
  166.             i = v*count_u + u;
  167.             mesh.SETPOINT(i, p);
  168.     }
  169.     }
  170.     button.layer.LOCKEXCLUSIVE(0);
  171.     button.layer.INSERT(0, 0, mesh);
  172.     button.layer.RELEASE(0);
  173. }
  174.  
  175.  
  176. // create a subdivision rectangle
  177.  
  178. function mycreSubdiv(button, event, value)
  179. {
  180.     sds = new r3Subdivision(0);
  181.     sds.SetPointCount(4);
  182.     sds.SetType(R3SUBDIVTYPE_POLYGONAL);
  183.     
  184.     sds.SETPOINT(0, new r3Vect(0.0, 0.0, 0));
  185.     sds.SETPOINT(1, new r3Vect(0.2, 0.0, 0));
  186.     sds.SETPOINT(2, new r3Vect(0.2, 0.2, 0));
  187.     sds.SETPOINT(3, new r3Vect(0.0, 0.2, 0));
  188.  
  189.     sds.MAKEFACE(4, [0, 1, 2, 3]);
  190.  
  191.     button.layer.LOCKEXCLUSIVE(0);
  192.     button.layer.INSERT(0, 0, sds);
  193.     button.layer.RELEASE(0);
  194. }
  195.  
  196.  
  197. // Constructor 
  198.  
  199. function myCreationTools(orientation)
  200. {
  201.     if(arguments.length == 0)
  202.         return;
  203.  
  204.     // create JavaScript interface for accessing geometric objects layer
  205.     primLayer = new r3Primlayer();
  206.     primLayer.r3Attach(Get("CurrentProject.Geometrics"));
  207.  
  208.     // let the super class to do its job
  209.     this.base = myToolBar; 
  210.     this.base("Creation Tools", VERTICAL, primLayer);
  211.  
  212.     // Add tool buttons.
  213.     this.AddTool("Camera",  mycreCamera);
  214.     this.AddTool("Sphere",  mycreSphere);
  215.     this.AddTool("Cone",    mycreCone);
  216.     this.AddTool("Rect",    mycreRect);
  217.     this.AddTool("Cube",    mycreCube);
  218.     this.AddTool("Pyramid", mycrePyramid);
  219.     this.AddTool("Nurbs",   mycreNurbs);
  220.     this.AddTool("Numesh",  mycreNumesh);
  221.     this.AddTool("SDS",     mycreSubdiv);
  222. }
  223.  
  224. myCreationTools.prototype=new myToolBar;
  225.